// pages/index/index.js
import {
  getHomeList
} from '../../apis/index';
import {
  getGoodsList
} from '../../apis/index'
Page({
  data: {
    indicatorDots: true,
    autoplay: true,
    interval: 2000,
    duration: 500,
    background: ['https://img0.baidu.com/it/u=4081976130,2879405245&fm=253&fmt=auto&app=138&f=JPEG?w=650&h=256', 'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.zcool.cn%2Fcommunity%2F01128c56fdd6de32f875a9443925d3.jpg%401280w_1l_2o_100sh.jpg&refer=http%3A%2F%2Fimg.zcool.cn&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1670988214&t=b83d9d85d907c0656e88315da3c8fc30', 'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.zcool.cn%2Fcommunity%2F013e175febd6a511013ee04d4e63e5.jpg%402o.jpg&refer=http%3A%2F%2Fimg.zcool.cn&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1670988214&t=4afe155ba49f7d144806964d6778a93c'],
    goodsList: [], //商品列表数据
    swpierList: [],
    show: false
  },
  onLoad(options) {
    console.log("123")
    this.initData()
  },
  async initData() {
    const res = await getHomeList()
    console.log("获取到的后台数据是", res)
    const pageData = res.data.pageData
    const swpierData = pageData.items[1].data
    console.log("轮播图的数据", swpierData)
    this.setData({
      swpierList: swpierData
    })
    const res1 = await getGoodsList()
    console.log("获取到的后台数据是", res1)
    const goodsDate = res1.data.list
    const goodsList = goodsDate.data
    console.log("商品列表", goodsList)
    this.setData({
      goodsList: goodsList
    })
    wx.hideLoading()
  },
  changeCate(e) {
    let index = e.target.dataset.index;
    this.setData({
      cateIndex: index
    })
  },
  shoppDetail(e) {
    //获取商品详情的商品id
    console.log(e.currentTarget.dataset.id)
    wx.navigateTo({
      url: './detail/index?goodsId=' + e.currentTarget.dataset.id,
    })
  },
  seachShopp() {
    wx.navigateTo({
      url: '/pages/seach/index',
    })
  },
 
})